package com.yichat.micro.msghttpservice.core.okHttp;

import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * Created by chenmohan on 2019/03/28
 *
 * @description
 */
@Configuration
public class OkHttpConfig {

    @Bean
    public OkHttpClient okHttpClient() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(5 * 1000, TimeUnit.MILLISECONDS) //链接超时
                .readTimeout(10 * 1000, TimeUnit.MILLISECONDS) //读取超时
                .writeTimeout(10 * 1000, TimeUnit.MILLISECONDS) //写入超时
                .build();
        okHttpClient.dispatcher().setMaxRequests(128);          //请求数最大128
        okHttpClient.dispatcher().setMaxRequestsPerHost(16);    //同一host的并发请求数16

        return okHttpClient;
    }


}
